package org.agony2d.gpu.supportClasses.textures {
	import flash.display.BitmapData;
	import flash.geom.Rectangle;
	import org.agony2d.debug.Logger;
	import org.agony2d.core.agony_internal;
	
	use namespace agony_internal;
	
public class TextureManager {
	
	agony_internal static function addFullTexture( fullTexName:String, BA:BitmapData, mipmapEnabled:Boolean ) : void {
		var fullTex:FullTexture
		
		fullTex = g_texList[fullTexName]
		if (!fullTex) {
			fullTex = g_texList[fullTexName] = new FullTexture(fullTexName)
			//Logger.reportMessage("TextureManager", "full tex ( " + fullTexName + " )..added")
		}
		fullTex.reset(BA, mipmapEnabled)
	}
	
	agony_internal static function addAtlas( fullTexName:String, atlasXml:XML ) : void {
		var fullTex:FullTexture
		
		fullTex = g_texList[fullTexName]
		if (!fullTex) {
			Logger.reportError("TextureManager", "addAtlas", "non existed full texture ( " + fullTexName + " )...")
		}
		fullTex.parseAtlasXml(atlasXml)
	}
	
	agony_internal static function addRegionTexture( fullTexName:String, name:String, region:Rectangle ) : void {
		var fullTex:FullTexture
		
		fullTex = g_texList[fullTexName]
		if (!fullTex) {
			Logger.reportError("TextureManager", "addRegionTexture", "non existed full texture ( " + fullTexName + " )...")
		}
		fullTex.addRegion(name, region, null)
	}
	
	agony_internal static function killTextures( texNames:Array ) : void {
		var tex:TextureProxy
		var texName:String
		
		if (texName.length == 0) {
			for each(tex in g_texList) {
				tex.dispose()
			}
			g_texList = {}
		}
		else {
			for each(texName in texNames) {
				tex = g_texList[texName]
				if (tex) {
					tex.dispose()
					delete g_texList[texName]
				}
			}
		}
	}
	
	agony_internal static var g_texList:Object = {}
}
}